package com.taiyuan.tongcheng.util;

import java.nio.channels.Selector;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import org.kymjs.kjframe.utils.KJLoger;

import com.taiyuan.tongcheng.bean.SelectDate;

//
public class TimeUtil {
	
	static SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
	static SimpleDateFormat formatter2 = new SimpleDateFormat("MM-dd E");
	 /**
     * 根据日期获得所在周的日期 
     * @param mdate
     * @return
     */
    public static List<Date> dateToWeek(Date mdate) {
        int b = mdate.getDay();
        Date fdate;
        List<Date> list = new ArrayList<Date>();
        Long fTime = mdate.getTime() - b * 24 * 3600000;
        for (int a = 1; a <= 7; a++) {
            fdate = new Date();
            fdate.setTime(fTime + (a * 24 * 3600000));
            list.add(a-1, fdate);
        }
        return list;
    }
    /**
     * 
    * @Description: 获取日期 集合
    * @param limitHour 预约limitHour开始的时间
    * @return
    * @return List<SelectDate>
    * @throws
    * @autour wzq
    * @date 2015-9-23 上午8:34:56
    * @update (date)
     */
	public static List<SelectDate> getList(int limitHour) {
		List<SelectDate> dataList = new ArrayList<SelectDate>();
		Date date = new Date();// 取时间
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		int currentHour=calendar.get(Calendar.HOUR_OF_DAY);
//		增加第一天时间
		if(currentHour>(23-limitHour)){
			calendar.add(calendar.DATE, 1);
		}else{
		}
		
		date = calendar.getTime(); 
		SelectDate selectDateTemp = new SelectDate();
		selectDateTemp.setDateLable(formatter2.format(date));
		selectDateTemp.setDateValue(formatter1.format(date)+" ");
		dataList.add(selectDateTemp);
	  //增加预知时间
		for (int a = 1; a <= 6; a++) {
			calendar.add(calendar.DATE, 1);// 把日期往后增加一天.整数往后推,负数往前移动
			date = calendar.getTime(); // 这个时间就是日期往后推一天的结果
			SelectDate selectDate = new SelectDate();
			selectDate.setDateLable(formatter2.format(date));
			selectDate.setDateValue(formatter1.format(date)+" ");
			dataList.add(selectDate);
		}
		return dataList;

	}
    
}
